require(['/js/config.js'],() => {
    require(['template','request','jquery'],(template,req) => {

        class indexPage{
			constructor() {
			    this.init()
			}
			init(){
				this.navHover()
				this.listBrash(template)
				this.getNav(template)
				this.startDraw()
			}
			//导航下拉菜单移入hover效果
			navHover(){
				$(".nav").hover(function(){
					$(".navList").slideDown()
				},
				function(){
					$(".navList").hover(function(){
					},
					function(){
						$(".navList").slideUp()
					})
				})
			}
			//列表数据获取
			listBrash(template){
				$.get("http://rap2.taobao.org:38080/app/mock/259711/index/brash",res=>{
					if(res.code === 200){
						this.brandList(res.data)
					
					}
				})
			}
			//列表渲染
			brandList(list){
				// console.log(list)
				const modelList = template("listUnitBrash",{list})
				$("#listUnitUl").html(modelList)
			}
			//nav数据获取调用渲染
			getNav(template){
				$.get(`${req.baseUrl}/tabs?sa=`,res=>{
					if(res.code===200){
						const navData = res.data.list.slice(1,7)
						this.navBrash(navData)
						this.navListBrash(navData)
					}
				})
			}
			//nav渲染
			navBrash(list){
				console.log(list)
				const navList = template("navUnit",{list})
				$("#navUl").html(navList)
			}
			//下拉菜单渲染
			navListBrash(res){
				$(".navList").html(template("navListBrash",{res}))
				console.log(res[0])
			}
			//抽奖页面
			startDraw(){
				$('.startDraw').on("click",()=>{
					$('.startDraw').parent('ul').fadeOut(800,()=>{
						$('.startNone').delay(700).fadeIn(500,()=>{
							$('.startNone').css("display","block")
						})
					})
				})
				$('.toReturn').on("click",()=>{
					$('.startNone').css("display","none")
					$('.startDraw').parent('ul').delay(700).fadeIn(1500,()=>{

					})
				})
			}
		}
		return new indexPage()
    })
})
